//
//  Tile.m
//  Tile
//
//  Created by MajorTom on 9/7/10.
//  Copyright iphonegametutorials.com 2010. All rights reserved.
//

#import "Tile.h"

@implementation Tile
@synthesize x, y, value, originalValue, sprite , x0 , y0;

-(id) initWithX: (NSInteger) posX Y: (NSInteger) posY{
	self = [super init];
	x = posX;
	y = posY;
    x0 = posX;
    y0 = posY;
    
    //NSLog(@"x = %d , y = %d",x , y);
	return self;
}

-(BOOL) nearTile: (Tile *)othertile{
	//NSLog(@"x self = %d , tmp x = %d",x , othertile.x);
    //NSLog(@"y self = %d , tmp y = %d",y , othertile.y);
    
    NSLog(@"x self = %d , tmp x = %d",x0 , othertile.x0);
    NSLog(@"y self = %d , tmp y = %d",y0 , othertile.y0);

    return 
	(x0 == othertile.x0 && abs(y0 - othertile.y0)==1)
	||
	(y0 == othertile.y0 && abs(x0 - othertile.x0)==1);
    
    
   // return YES;
}

-(void) trade: (Tile *)otherTile{
	CCSprite *tempSprite = [sprite retain];
	int tempValue = value;
	self.sprite = otherTile.sprite;
	self.value = otherTile.value;
	otherTile.sprite = tempSprite;
	otherTile.value = tempValue;
	[tempSprite release];
}

-(CGPoint) pixPosition{
	return ccp(kStartX + x * kTileSize +kTileSize/2.0f,kStartY + y * kTileSize +kTileSize/2.0f);
}
@end
